const { Builder, By, until } = require('selenium-webdriver');
// let chrome = require('selenium-webdriver/chrome');
let firefox = require('selenium-webdriver/firefox');
// let driver = new Builder()
//     .forBrowser('chrome')
//     // .setChromeOptions(new chrome.Options().headless())
//     .build();

var driver = new Builder()
    .forBrowser('firefox')
    .setFirefoxService(new firefox.ServiceBuilder("./geckodriver.exe"))
    // .setFirefoxOptions(new firefox.Options().headless())
    .build();



let timeout = 10000

async function init(cookies) {
    
    await driver.get('https://app.yinxiang.com/Login.action');
    driver.findElement(By.id('username')).sendKeys('cuipp0509@hotmail.com');
    driver.findElement(By.id('loginButton')).click();
    // 等待密码框可以输入
    await driver.wait( async () => { 
        let ele = await driver.findElement(By.id('password'))
        let isEnabled = await ele.isEnabled()
        return isEnabled
    }, timeout, `timeout ${timeout}`)
    driver.findElement(By.id('password')).sendKeys('Alskdjfhg405');
    driver.findElement(By.id('loginButton')).click();
    // 等待页面加载完成，直到用户名出现 /* 请先设置显示样式为旧版 */
    // let username = await driver.wait(until.elementTextIs(By.xpath('//*[@id="header-wrapper"]/div/div/div[2]/div/a/div[1]/div/span', 'cuipp0509@hotmail.com')), timeout)
    // console.log('username :>> ', username);
    // 待等弹窗加载完成
    // let alertButton = await driver.wait(until.elementLocated(By.id('lightbox-glass')), timeout)
    // let alertButton = await driver.findElement(By.id('opt-out'))
    // if (alertButton) {
    //     alertButton.click()
    // }
    // 读取指定笔记本里面的指定文章

    
}

// 印象笔记 cookies
let cookies = '_ga=GA1.2.1915245358.1606206963; MONITOR_WEB_ID=27e62e65-e7bd-4565-aae6-ef5131444555; passport_csrf_token_default=eb1e5344294aa01c0a1128cd633405c9; passport_csrf_token=eb1e5344294aa01c0a1128cd633405c9; sid_guard=3f72bb3be376f062f9e83728bc3378f2|1637650349|5184000|Sat,+22-Jan-2022+06:52:29+GMT; uid_tt=9463d9ada8665d92f23fb495a63c5ba2; uid_tt_ss=9463d9ada8665d92f23fb495a63c5ba2; sid_tt=3f72bb3be376f062f9e83728bc3378f2; sessionid=3f72bb3be376f062f9e83728bc3378f2; sessionid_ss=3f72bb3be376f062f9e83728bc3378f2; sid_ucp_v1=1.0.0-KDBjNmM1MDA3NGFjZjdhODBlOTc2N2QwMmEwYjlhNzE3YWM0OWIyNDYKFgj-_eDlq_XzBBCtn_KMBhiwFDgIQAsaAmxmIiAzZjcyYmIzYmUzNzZmMDYyZjllODM3MjhiYzMzNzhmMg; ssid_ucp_v1=1.0.0-KDBjNmM1MDA3NGFjZjdhODBlOTc2N2QwMmEwYjlhNzE3YWM0OWIyNDYKFgj-_eDlq_XzBBCtn_KMBhiwFDgIQAsaAmxmIiAzZjcyYmIzYmUzNzZmMDYyZjllODM3MjhiYzMzNzhmMg; n_mh=ekp69lUm7YLR9eOGUH5UPGU97CbzXvVzhDVv7bHmV_4';


init(cookies)
